package com.emmmya.ocs.common.base;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.emmmya.harinCheck.annotation.Check;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 *
 * @author: 咕噜肉IT小店-黑医
 * @createDate: 2022-05-17
 * @version: 1.0
 */
@Data
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"})
public class BaseEntity implements Serializable {

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(value = "id",type= IdType.AUTO)
    private Long id;

    @CreatedBy
    @Column(name="create_by")
    @TableField(value = "create_by", fill = FieldFill.INSERT)
    @Check(name="创建人")
    private String createBy;

    /**
     * 创建时间
     * 在执行insert语句时候自动插入，jpa审计
     */
    @CreatedDate
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name="create_time")
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    @Check(name="创建时间")
    private Date createTime;

    /**
     * 更新人
     * 最后修改人
     */
    @LastModifiedBy
    @Column(name="update_by")
    @TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE) // 新增和更新执行
    @Check(name="更新人")
    private String updateBy;

    /**
     * 更新时间
     * 最后一次修改时间
     */
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @LastModifiedDate
    @Column(name="update_time")
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) // 新增和更新执行
    @Check(name="更新时间")
    private Date updateTime;

    /**
     *  0是正常  1是删除  -1 是禁用
     */
    private Integer delFlag = 0;
}
